import { _decorator, Component, Node, director, Button, sys } from 'cc';
import { ResMgr } from '../../../Framework/Scripts/Managers/ResMgr';
import { SoundMgr } from '../../../Framework/Scripts/Managers/SoundMgr';
import { UIComponent, UIMgr } from '../../../Framework/Scripts/Managers/UIMgr';
import { GameApp } from '../GameApp';
const { ccclass, property } = _decorator;


/** 
  周无邪出品
  本源码用于学习研究使用。
  作者联系方式：tuya7078（微信）。
 */
@ccclass('GameOver_UICtrl')
export class GameOver_UICtrl extends UIComponent {
    private str: Node = null
    start() {

    }
    onLoad() {
        this.ViewNode("fuhuoBtn").getComponent(Button).interactable = true
        this.ViewNode("rePlay").getComponent(Button).interactable = true
        this.ViewNode("outBtn").getComponent(Button).interactable = true
        this.str = this.ViewNode("str")

        SoundMgr.Instance.stopBgMusic()

        SoundMgr.Instance.playSound(ResMgr.Instance.getAsset("Sounds", "fail"))


        if (GameApp.Instance.playerTs.isDie) {
            this.str.active = false
            //挂了才有复活


            this.AddButtonListener("fuhuoBtn", this, () => {
           
                    this.ViewNode("fuhuoBtn").getComponent(Button).interactable = false
                    this.ViewNode("rePlay").getComponent(Button).interactable = false
                    this.ViewNode("outBtn").getComponent(Button).interactable = false
                    director.resume()
                    GameApp.Instance.playerTs.fuhuo()
                    UIMgr.Instance.DestroyUIView(this.node.name)
           




            })
        } else {
            this.ViewNode("fuhuoBtn").active = false
            this.str.active = true
            //建筑物被摧毁
        }


        this.AddButtonListener("rePlay", this, () => {
            director.resume()
            GameApp.Instance.stopTimer()
            GameApp.Instance.delAll()
            UIMgr.Instance.DestroyUIView(this.node.name)
            GameApp.Instance.StartGame()

        })
        this.AddButtonListener("outBtn", this, () => {
            director.resume()
            GameApp.Instance.stopTimer()
            GameApp.Instance.delAll()
            UIMgr.Instance.DestroyUIView(this.node.name)
            GameApp.Instance.enterGame()

        })
        director.pause()
    }


    update(dt: number) {

    }
}


